#ifndef TINYSTL_VECTOR_H
#define TINYSTL_VECTOR_H

namespace mystl
{
    template<class T>
    class vector
    {
        static_assert(!std::is_same<bool, T>::value, "vector<bool> is abandoned in mystl");
    public:
        typedef mystl::allocator<T>         allocator_type;	/*! 分配器 */
        typedef mystl::allocator<T>         data_allocator;

        typedef typename allocator_type::value_type     value_type;
        typedef typename allocator_type::pointer        pointer;
        typedef typename allocator_type::const_pointer  const_pointer;
        typedef typename allocator_type::reference      reference;
        typedef typename allocator_type::const_reference const_reference;
        typedef typename allocator_type::size_type      size_type;
        typedef typename allocator_type::difference_type difference_type;

        typedef value_type*                             iterator;
        typedef const value_type*                       const_iterator;
        typedef mystl::reverse_iterator<iterator>       reverse_iterator;
        typedef mystl::reverse_iterator<const_iterator> const_reverse_iterator;

        allocator_type get_allocator() { return data_allocator(); }

    private:
        iterator begin_;
        iterator end_;
        iterator cap_;

    public:
        vector() noexcept
        {
            try_init();
        }

        explicit vector(size_type n)
        {
            fill_init(n, value_type());
        }

    private:
        void try_init() noexcept;

    };

    // try_init 函数，若分配失败则忽略，不抛出异常
    template<class T>
    void vector<T>::try_init() noexcept
    {
        try
        {
            begin_ = data_allocator::allocate(16);
            end_ = begin_;
            cap_ = begin_ + 16;
        }
        catch (...)
        {
            begin_ = nullptr;
            end_ = nullptr;
            cap_ = nullptr;
        }
    }

} // namespace mystl


#endif